package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsRegion;
import com.qf.service.AdministrativeService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin("*")
@RestController
@RequestMapping("/region")
public class AdministrativeController {

    @Autowired
    private AdministrativeService administrativeService;

    @GetMapping("/list")
    public Object list(String name,String code,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "20") Integer limit
    ){

    //1查询并返回分页对象
        IPage<DtsRegion> resultPage = administrativeService.queryRegionPage(name,code,page,limit);
        //获取结果集
        List<DtsRegion> list = resultPage.getRecords();
        //获取查询总条数
        long total = resultPage.getTotal();
        //封装对象返回
        Map<String,Object> data = new HashMap<>();
        data.put("total",total);
        data.put("items",list);
        return ResponseUtil.ok(data);

    }

}
